package org.example.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.example.entity.Product;
import org.example.entity.Shanpinfele;
import org.example.result.Pages;

import java.util.List;

@Mapper
public interface Shanpinfelemapper {


    /**
     * 商品分类分页查询
     * @param pages
     * @return
     */
    Page<Shanpinfele> pageQuery(Pages pages);

    /**
     * 新增分类
     * @param shanpinfele
     */
    @Insert("INSERT INTO shanpinfele (name,status,zhongshu,create_time,update_time,username)\n" +
            "VALUES\n" +
            "(#{name}, #{status},#{zhongshu},#{createTime},#{updateTime},#{username})")
    void add(Shanpinfele shanpinfele);


    /**
     * 批量删除
     *
     * @param name
     * @param status
     * @param username
     */
    void delete(String name, String status, String username);

    /**
     * 分类查询
     *
     * @param name
     * @param username
     * @return
     */
    @Select("select * from shanpinfele where name=#{name} and username=#{username}")
    Shanpinfele felecx(String name, String username);

    /**
     * 分类修改
     * @param shanpinfele
     */
    void felexg(Shanpinfele shanpinfele);

    /**
     * 删除分类
     * @param id
     */
    @Delete("DELETE FROM shanpinfele"
            +" WHERE id=#{id}")
    void felesc(int id);

    /**
     * name查询
     * @param username
     * @return
     */
    @Select("select name from shanpinfele where username=#{username} and status!=0")
    String[] felenamecx(String username);

    /**
     * 数查询
     * @return
     */
    @Select("select zhongshu from shanpinfele where username=#{username} and name=#{name}")
    int feleshucx(String name,String username);

    @Update("UPDATE shanpinfele\n" +
            "SET zhongshu = #{shu}\n" +
            "WHERE name=#{specs} and username=#{username}")
    void feleshuxg(String specs, String username, int shu);


    /**
     * 批量中数
     * @param name
     * @param status
     * @param username
     */
    List<Shanpinfele> felelist(String name, String status, String username);

    /**
     * 查询商品
     * @param id
     * @return
     */
    @Select("select * from shanpin where id=#{id}")
    Product cxshanpin(int id);

    /**
     * 启数目
     * @param username
     * @return
     */
    @Select("select count(*) from shanpinfele where username=#{username} and status=1")
    int shuqcx(String username);

    @Select("select count(*) from shanpinfele where username=#{username} and status=0")
    int shutcx(String username);

    @Delete("delete from shanpinfele where username=#{username} ")
    void deletes(String username);
}
